package com.zst.sw.server.module.segmentref;

import com.google.common.collect.Lists;
import org.apache.skywalking.apm.network.language.agent.v3.SegmentReference;

import java.util.Collections;
import java.util.List;

public class SegmentRefMapper {
    public static List<SegmentRef> map(List<SegmentReference> list) {
        if (list == null) {
            return Collections.emptyList();
        }

        List<SegmentRef> ret = Lists.newArrayListWithExpectedSize(list.size());
        for (SegmentReference segmentReference : list) {
            ret.add(map(segmentReference));
        }
        return ret;
    }

    public static SegmentRef map(SegmentReference segmentReference) {
        if (segmentReference == null) {
            return null;
        }

        SegmentRef segmentRef = new SegmentRef();
        segmentRef.setRefType(segmentReference.getRefType().getNumber());
        segmentRef.setTraceId(segmentReference.getTraceId());
        segmentRef.setParentTraceSegmentId(segmentReference.getParentTraceSegmentId());
        segmentRef.setParentSpanId(segmentReference.getParentSpanId());
        segmentRef.setParentService(segmentReference.getParentService());
        segmentRef.setParentServiceInstance(segmentReference.getParentServiceInstance());
        segmentRef.setParentEndpoint(segmentReference.getParentEndpoint());
        return segmentRef;
    }

}
